

    let edit = tbody.getElementsByClassName("btn-edit")
    let del = tbody.getElementsByClassName("btn-del")
    let ok = tbody.getElementsByClassName("btn-ok")
    let cancel = tbody.getElementsByClassName("btn-cancel")
    let tr = tbody.getElementsByTagName("tr")
    
    prom('./api/v1/shop/select.php').then(reg => {
        
        if(reg.code === 200){
            const {list} = reg.body
            console.log(list);
           
            for(var i=0;i<list.length;i++){
                edit[i].index = i;
                edit[i].onclick = function(){
                this.style.display =  'none'
                del[this.index].style.display =  'none'
                ok[this.index].style.display =  'inline-block'
                cancel[this.index].style.display =  'inline-block'
               
                let inp = tr[this.index].getElementsByTagName("input")
                let span = tr[this.index].getElementsByTagName("span")
                let id = tr[this.index].getAttribute('idx')
                
                for(var j=0;j<3;j++){
                    span[j].style.display =  'none'
                    inp[j].style.display =  'inline-block'
                    inp[j].value = span[j].innerHTML
                }
                //点击确定修改
                ok[this.index].onclick = () =>{
                    let name = inp[0].value
                    let price = inp[1].value
                    let num = inp[2].value
                   
                     //数据发送到后端
                    prom('./api/v1/shop/edit.php',{id,name,price,num}).then(reg => {
                        if(reg.code === 200){
                            //传输成功，重新渲染页面
                             getData()
                        }else{
                            console.log("失败");
                            
                        } 
                    })
                }
                //取消修改
                cancel[this.index].onclick = () =>{
                    this.style.display =  'inline-block'
                    del[this.index].style.display =  'inline-block'
                    ok[this.index].style.display =  'none'
                    cancel[this.index].style.display =  'none'

                    for(var w=0;w<3;w++){
                        span[w].style.display =  'inline-block'
                        inp[w].style.display =  'none'
                    }
                }
               }
                //点击删除
                del[i].dex = i;
                del[i].onclick =function(){
                    //id发送到后端
                    let idx = tr[this.dex].getAttribute('idx')
                   
                    prom('./api/v1/shop/delete.php',{idx}).then(reg => {
                        if(reg.code === 200){
                            //传输成功，重新渲染页面
                            getData()
                        }else{
                            console.log("失败");
                            
                        } 
                    })
                }
             }
        }   
    })   
  

